
package hasthi.wsdm.capabilities;

import hasthi.common.HasthiException;
import hasthi.common.XmlBeanUtils;
import hasthi.common.HasthiException.FaultCode;
import hasthi.wsdm.CapabilityDescription;
import hasthi.wsdm.ManagableResource;
import hasthi.wsdm.ManagementAgentContext;

import javax.xml.namespace.QName;

import org.w3.x2005.x08.addressing.EndpointReferenceType;

import wsdm.mows.GetManageabilityReferencesDocument;
import wsdm.mows.GetManageabilityReferencesResponseDocument;
import wsdm.mows.GetManageabilityReferencesResponseDocument.GetManageabilityReferencesResponse;

public class ManageabilityReferenceCapability extends AbstractCapability{
    @Override
    public void init(ManagementAgentContext context, ManagableResource ownedResource, CapabilityDescription description) throws HasthiException {
        super.init(context, ownedResource, description);
    }


    public GetManageabilityReferencesResponseDocument getManageabilityReferences(GetManageabilityReferencesDocument request){
        //Return my address as managability endpoint
        GetManageabilityReferencesResponseDocument responseDocument = GetManageabilityReferencesResponseDocument.Factory.newInstance();
        GetManageabilityReferencesResponse response = responseDocument.addNewGetManageabilityReferencesResponse();
        EndpointReferenceType myEpr = ownedResource.getResourceEndpointEPR();
        XmlBeanUtils.addElementAsChild(response.addNewManageabilityEndpointReference(), myEpr);
        return responseDocument;
    }
    
    public void setProperty(QName name, Object value) throws HasthiException {
        throw new HasthiException("Unsupported property "+name + " set in capability "+ this,FaultCode.InvaliedLocalArgumnet);
    }
   
    public Object getProperty(QName name) throws HasthiException {
        throw new HasthiException("Unsupported property "+name + " requested from capability "+ this,FaultCode.InvaliedLocalArgumnet);
    }
    
}

